package pers.cz.postgirl.adapter.geequery;

import pers.cz.postgirl.adapter.AbstractTransformer;
import pers.cz.postgirl.config.EvenType;
import pers.cz.postgirl.core.EnhanceModel;

/**
 * @program: postgirl-client
 * @description: geequery适配器
 * @author: Cheng Zhi
 * @create: 2023-06-18 21:26
 **/
public class GeequeryPlugin extends AbstractTransformer {

    @Override
    public void loadEnhanceModel() {
        enhanceModel = EnhanceModel.builder()
                .classPattern("org.easyframe.enterprise.spring.CommonDaoImpl")
                .methodPatterns(getMethodPattern())
                .build();
    }

    private EnhanceModel.MethodPattern[] getMethodPattern() {

        EnhanceModel.MethodPattern remove = EnhanceModel.MethodPattern.builder()
                .methodName("remove")
                .paramTypes(new String[] {"java.lang.Object"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern find = EnhanceModel.MethodPattern.builder()
                .methodName("find")
                .paramTypes(new String[] {"java.lang.Object"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();

        EnhanceModel.MethodPattern insert = EnhanceModel.MethodPattern.builder()
                .methodName("insert")
                .paramTypes(new String[] {"java.lang.Object"})
                .evenTypes(new EvenType[] {EvenType.BEFORE, EvenType.RETURN})
                .build();


        return new EnhanceModel.MethodPattern[] {
                remove,
                find,
                insert
        };
    }
}
